VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "FTPCallback"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit

'----------------------------------------------------
'<Purpose> callback function that is used to show the
' FTPServer files and directories in the ListView
'----------------------------------------------------
Public Function ListFTPItems(ThisSession As Form, ThisExplorer As Form, ServerNode As Node)
    Dim IsDir           As Boolean
    Dim InstanceFile    As CIFTPLib.File
    Dim i               As Integer
    Dim ListCount       As Integer
    Dim TheseItems      As ListItems
    Dim WorkingItem     As ListItem
    Dim TheseNodes      As Nodes
    Dim WorkingNode     As Node
    Dim DirKey          As String
    Dim FormattedSize   As String
    Dim FullPathName    As String
    Dim ItemKey         As String
    Dim ListItem        As String
    Dim NodeKey         As String
    Dim ServerKey       As String
    Dim WorkingDir      As String
    
    '----- cache data
    ServerKey = ServerNode.Key
    WorkingDir = ThisSession.WorkingDir
    
    '---- cache explorer objects
    Set TheseNodes = ThisExplorer.Tree.Nodes
    Set TheseItems = ThisExplorer.List.ListItems
    
    On Error GoTo BadFile
    
    '---- add all files and create extra data for each
    DirKey = ThisSession.ciSession.WorkingDirectory & "/"
    For Each InstanceFile In ThisSession.ciSession.Files
        ListItem = InstanceFile.FileName
        If (ListItem <> "") Then
            IsDir = (InstanceFile.Attributes And FTP_ATTRIB_DIRECTORY)
        
            If IsDir Then
                If ((ListItem <> ".") And (ListItem <> "..")) Then
                
                    '---- concatenate the full path
                    If (WorkingDir = "/") Then
                        FullPathName = "/" & ListItem
                    Else
                        FullPathName = WorkingDir & "/" & ListItem
                    End If
                    
                    NodeKey = ServerKey & "." & ListItem
                    
                    If (Not IsKeyed(TheseNodes, NodeKey)) Then
                        Set WorkingNode = TheseNodes.Add(ServerNode, tvwChild, NodeKey, ListItem, imgFolderClosed, imgFolderOpen)
                        
                        '---- add extra data
                        Dim ThisAttachment As New Attachment
                        ThisAttachment.NodeType = nodFTPFolder
                        ThisAttachment.DrivePath = FullPathName
                        Set ThisAttachment.Session = ThisSession
                        Call ThisExplorer.Attachments.Add(ThisAttachment, NodeKey)
                        Set ThisAttachment = Nothing
                        
                        '---- add searching placeholder
                        Call TheseNodes.Add(WorkingNode, tvwChild, WorkingNode.Key & nodPlaceHolder, nodPlaceHolder, imgPlaceHolder)
                    End If
                    
                    '---- add directory to ListView; pad with invisible char for sorting purposes
                    Set WorkingItem = TheseItems.Add(, NodeKey, Chr(160) & ListItem, imgFolderClosed, imgFolderClosed)
                    '---  add type, size, and modified bits to item
                    'WorkingItem.SubItems(1) = Str(FileLen(FullPathName) \ 1024) & "KB"
                    WorkingItem.SubItems(2) = "FTP File Folder"
                    'WorkingItem.SubItems(3) = Format(FileDateTime(FullPathName), "General Date")
                End If
            Else
                ItemKey = DirKey & ListItem
            
                '---- add directory to ListView; pad with invisible char for sorting purposes
                Set WorkingItem = TheseItems.Add(, ItemKey, ListItem, imgFTPFile, imgFTPFile)
                WorkingItem.Tag = ServerNode.Key
        
                '---  add type, size, and modified bits to item
                FormattedSize = Str((InstanceFile.FileSize \ 1024) + 1) & "KB"
                'If (FormattedSize = " 0KB") Then FormattedSize = " 1KB"
                WorkingItem.SubItems(1) = FormattedSize
                WorkingItem.SubItems(2) = "FTP File"
                WorkingItem.SubItems(3) = Format(InstanceFile.FileDate, "General Date")
            End If
        End If
    Next
    
Cleanup:
    Set InstanceFile = Nothing
    Set TheseItems = Nothing
    Set TheseNodes = Nothing
    Set WorkingItem = Nothing
    Set WorkingNode = Nothing

    ThisExplorer.MousePointer = vbDefault
    
    On Error GoTo 0
    Exit Function
    
BadFile:
    GoTo Cleanup
    
End Function

